//
//  ALPS_TSearchAllTCell.m
//  Alps
//
//  Created by dllo on 16/6/16.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "ALPS_TSearchAllTCell.h"
#import "ALPS_TSAlbumCCell.h"
#import "ALPS_TSVoiceCCell.h"
@implementation ALPS_TSearchAllTCell


-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.arrowView = [[UIImageView alloc] init];
        self.arrowView.image = [UIImage imageNamed:@"toolbar_play_n"];
        [self.contentView addSubview:_arrowView];
        
        self.titleLabel = [[UILabel alloc] init];
        self.titleLabel.text = @"专辑";
        [self.contentView addSubview:_titleLabel];
        
        self.introduceLabel = [[UILabel alloc] init];
        self.introduceLabel.textColor = [UIColor grayColor];
        self.introduceLabel.textAlignment = 2;
        self.introduceLabel.font = [UIFont systemFontOfSize:13];
        [self.contentView addSubview:_introduceLabel];
        
        self.arrowRightView = [[UIImageView alloc] init];
        self.arrowRightView.image = [UIImage imageNamed:@"xm_accessory"];
        [self.contentView addSubview:_arrowRightView];
        
        UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
        flowLayout.itemSize = CGSizeMake(ScreeWidth, 100);
        flowLayout.minimumLineSpacing = 0;
        flowLayout.minimumInteritemSpacing = 0;
        flowLayout.scrollDirection = UICollectionViewScrollDirectionVertical;
        
        self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 45, ScreeWidth, 300) collectionViewLayout:flowLayout];
        self.collectionView.dataSource = self;
        self.collectionView.delegate = self;
        self.collectionView.scrollEnabled = NO;
        [self.contentView addSubview:_collectionView];
        self.collectionView.backgroundColor = [UIColor colorWithRed:0.96 green:0.96 blue:0.96 alpha:1.00];
        
        [self.collectionView registerClass:[ALPS_TSAlbumCCell class] forCellWithReuseIdentifier:@"ALPS_TSAlbumCCell"];
        
        [self.collectionView registerClass:[ALPS_TSVoiceCCell class] forCellWithReuseIdentifier:@"ALPS_TSVoiceCCell"];
        
        
        
        self.lineLabel = [[UILabel alloc] init];
        self.lineLabel.backgroundColor = [UIColor colorWithRed:0.80 green:0.80 blue:0.80 alpha:1.00];
        [self.contentView addSubview:_lineLabel];
        
        
    }

    return self;
}

-(void)layoutSubviews
{
    [super layoutSubviews];
    
    [self.arrowView makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).offset(0);
        make.left.equalTo(self.contentView).offset(0);
        make.width.equalTo(50);
        make.height.equalTo(50);
    }];
    
    [self.titleLabel makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).offset(12);
        make.left.equalTo(self.arrowView.right).offset(0);
        make.right.equalTo(self.contentView).offset(-200);
        make.height.equalTo(27);
        
    }];
    
    [self.introduceLabel makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).offset(12);
        make.right.equalTo(self.contentView).offset(-30);
        make.left.equalTo(self.titleLabel.right).offset(0);
        make.height.equalTo(27);
    }];
    
    [self.arrowRightView makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).offset(18);
        make.right.equalTo(self.contentView).offset(-10);
        make.width.equalTo(7);
        make.height.equalTo(14);
    }];
    
    [self.lineLabel makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.collectionView.bottom).equalTo(0);
        make.left.equalTo(self.contentView).offset(0);
        make.width.equalTo(self.contentView.width);
        make.height.equalTo(5);
    }];

}


-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
   
    return self.dataSource.count;
}

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    if (self.type == 1) {
        ALPS_TSAlbumCCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"ALPS_TSAlbumCCell" forIndexPath:indexPath];
        cell.model = [self.dataSource objectAtIndex:indexPath.row];
        return cell;
    }
    else
    {
        ALPS_TSVoiceCCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"ALPS_TSVoiceCCell" forIndexPath:indexPath];
        cell.model = [self.dataSource objectAtIndex:indexPath.row];
        return cell;
    }
    
    
}


-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    self.jump(indexPath.row);

}

-(void)setDataSource:(NSMutableArray *)dataSource
{
    if (_dataSource != dataSource) {
        _dataSource = dataSource;
    }
    self.collectionView.frame = CGRectMake(0, 45, ScreeWidth, self.dataSource.count * 100);
    [self.collectionView reloadData];

}


- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
